package com.hhkj.study.admin.dict.controller;

import cn.hutool.core.util.StrUtil;
import com.hhkj.study.admin.dict.entity.DictMultiLevel;
import com.hhkj.study.admin.dict.model.req.DictMultiLevelReq;
import com.hhkj.study.admin.dict.model.res.DictMultiLevelRes;
import com.hhkj.study.admin.dict.service.biz.DictMultiLevelBizService;
import com.ruoyi.common.annotation.PermissionPrefix;
import com.ruoyi.common.base.biz.controller.v3.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.valid.VDisable;
import com.ruoyi.common.valid.VEdit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
* DictMultiLevelController
*
* @author SERVER
* @since 2024-09-06
*/
@RestController
@PermissionPrefix("dict:dictMultiLevel")
@Controller
@RequestMapping("/admin/dict/multi/level")
public class DictMultiLevelController extends BaseController<DictMultiLevel, DictMultiLevelReq, DictMultiLevelRes, DictMultiLevelBizService> {

    /** 树型列表 */
    @PostMapping("/code/list")
    public TableDataInfo listTreeAll(@RequestBody DictMultiLevelReq req) {
        if (StrUtil.isBlank(req.getTypeCode())) {
            throw new GlobalException("typeCode参数缺失");
        }
        return getDataTable(this.getBizService().listTreeAll(req));
    }

    /** 禁用/启用 */
    @PreAuthorize("@ss.hasPermi(this, 'edit')")
    @PutMapping("/disable/flag")
    public AjaxResult updateDisableFlag(@Validated(value = {VEdit.class, VDisable.class}) @RequestBody DictMultiLevelReq req) {
        return toAjax(this.getBizService().updateDisableFlag(req));
    }
}
